package butines.core.game;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class GameEntityManager {

	private Map<Integer, GameEntity> entitiesMap = new HashMap<Integer, GameEntity>();
	private List<GameEntity> entitiesList = new ArrayList<GameEntity>();
	
	public void addEntity(GameEntity entity) {
		entitiesMap.put(entity.getId(), entity);
		entitiesList.add(entity);
	}

	public void removeEntity(GameEntity entity) {
		entitiesMap.remove(entity.getId());
		entitiesList.add(entity);
	}

	@SuppressWarnings("unchecked")
	public <T extends GameEntity> T getEntityFromID(int id) {
		return (T) entitiesMap.get(id);
	}
	
	public Iterator<GameEntity> getEntities() {
		return entitiesList.iterator();
	}
	
	public void reset(){
		entitiesMap.clear();
	}
	
}
